// 商品接口
const express = require("express");
const pool = require("../pool.js");
const c = express.Router();



// 商品显示
c.get("/list/:lid", (req, res) => {
  // 获取lid的
  let obj = req.params;
  let num = Number(obj.lid);
  let value = (num - 1) * 8;
  // console.log( value);
  // 查找数据库的数据  每页8个内容
  pool.query("select * from commodity limit ?,8", [value], (err, result) => {
    if (err) throw err;
    // console.log(result);
    res.send({
      code: 200,
      msg: result,
    });
  });
});
// 价格
c.get("/price/:lid", (req, res) => {
  // 获取lid的值
  let obj = req.params;
  let num = Number(obj.lid);
  let value = (num - 1) * 8;
  // console.log(value)
  // 查找数据库的数据  每页4个内容 以价格降序排列
  pool.query(
    "select * from commodity order by com_price limit ?,8",
    [value],
    (err, result) => {
      if (err) throw err;
      // console.log(result);
      res.send({
        code: 200,
        msg: result,
      });
    }
  );
});
// 添加到购物车
c.put("/add/:sid", (req, res) => {
  // 得到的参数
});

module.exports = c;
